﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.ActiveRecord;

namespace ServiceGerenciador.Model
{
    [Serializable]
    [ActiveRecord("funcionarioServicos")]
    public class FuncionarioServicos : ActiveRecordBase<FuncionarioServicos>
    {
        public FuncionarioServicos()
        {

        }

        [PrimaryKey]
        public int Id { get; set; } 
       
        [BelongsTo("IdPessoa")]
        public Funcionario Pesfs { get; set; }

        [BelongsTo("IdServico")]
        public Service Servicofs { get; set; }

        public string nomeservicofs
        {
            get
            {
                if (this.Servicofs != null)
                    return this.Servicofs.servico;
                else
                    return string.Empty;
            }
        }

        public string nomepesfs
        {
            get
            {
                if (this.Pesfs != null)
                    return this.Pesfs.Nome;
                else
                    return string.Empty;
            }
        }

        public static FuncionarioServicos[] Pesquisa(string termo)
        {
            var servico = FindAll();
            return servico.Where((s) => (s.Servicofs.servico.ToUpper().Contains(termo.ToUpper()))).ToArray();            
        }
    }
}